import java.util.Arrays;
import java.util.Scanner;

/**
 * @author gao
 * @date 2025/9/4 8:55
 */

public class Solution {
    public int maxSumRangeQuery(int[] nums, int[][] requests) {
        int n = nums.length, mod = (int)1e9 + 7;

        // 使用差分数组统计每个位置的操作数
        int[] diff = new int[n + 1];
        for (int[] req : requests) {
            int start = req[0], end = req[1];
            diff[start]++;
            if (end + 1 < n) {
                diff[end + 1]--;
            }
        }

        // 计算前缀和，统计每个位置的操作数
        int[] dp = new int[n];
        dp[0] = diff[0];
        for (int i = 1; i < n; i++) {
            dp[i] = dp[i - 1] + diff[i];
        }

        // 排序
        Arrays.sort(nums);
        Arrays.sort(dp);

        // 计算最大和
        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += (long) nums[i] * dp[i];
            sum %= mod;
        }

        return (int) sum;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int q = in.nextInt();
            int[] nums = new int[q];

            for (int i = 0; i < nums.length; i++) {
                nums[i] = in.nextInt();
            }

            int m = in.nextInt();
            int n = in.nextInt();
            int[][] requests = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    requests[i][j] = in.nextInt();
                }
            }

            Solution solution = new Solution();
            System.out.println(solution.maxSumRangeQuery(nums, requests));
        }
    }
}